package stu.wingsmaker.artofsubway.view.activity;

import stu.wingsmaker.artofsubway.R;
import stu.wingsmaker.artofsubway.view.ConcertListFragment;
import stu.wingsmaker.artofsubway.view.CultureListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
import com.actionbarsherlock.view.SubMenu;

public class InfoActivity extends SherlockFragmentActivity {
	FragmentManager fragmentManager;
	FragmentTransaction fragmentTransaction;
	FragmentTransaction ft;
	Fragment fragment;
	ConcertListFragment concertF = new ConcertListFragment();
	CultureListFragment cultureF = new CultureListFragment();
//	SettingListFragment settingF = new SettingListFragment();
//	FavoriteListFragment favoriteF = new FavoriteListFragment();
	Intent intent;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		setContentView(R.layout.activity_info);
		intent = getIntent();
		
		String title = intent.getStringExtra("genre");
		Log.i("TAG", title);
		fragmentManager = getSupportFragmentManager();
		fragmentTransaction = fragmentManager.beginTransaction();
		
		
		if(title.equals("concert")) {
			fragmentTransaction.add(R.id.frameLayoutFragment, concertF);
			
		} else if (title.equals("culture")) {
			fragmentTransaction.add(R.id.frameLayoutFragment, cultureF);
			
		} else if (title.equals("favorite")) {
			//fragmentTransaction.add(R.id.frameLayoutFragment, favoriteF);
 		} else if(title.equals("setting")) {
 			//fragmentTransaction.add(R.id.frameLayoutFragment, settingF);
 		}
		fragmentTransaction.commit();
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		SubMenu submenu = menu.addSubMenu(null);
        submenu.add(getResources().getString(R.string.concert)).setIcon(R.drawable.abs__ic_search);
        submenu.add(getResources().getString(R.string.culture)).setIcon(R.drawable.abs__ab_stacked_solid_dark_holo);
        submenu.add(getResources().getString(R.string.favorite)).setIcon(R.drawable.abs__ic_menu_share_holo_dark);
        submenu.add(getResources().getString(R.string.setting)).setIcon(R.drawable.action_settings);
        
        MenuItem ShareButton = submenu.getItem();
        ShareButton.setIcon(R.drawable.abs__ic_menu_moreoverflow_holo_dark);
        ShareButton.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

		
        MenuItem concertItem = submenu.getItem(0);
        concertItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        concertItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			
			@Override
			public boolean onMenuItemClick(MenuItem item) {
				// TODO Auto-generated method stub
				  // 프래그먼트 교체 기능 넣기 
				ft = fragmentManager.beginTransaction().replace(R.id.frameLayoutFragment, concertF);
				ft.addToBackStack(null);
				ft.commit();
				return false;
			}
		});
        MenuItem cultureItem = submenu.getItem(1);
        cultureItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        cultureItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			
			@Override
			public boolean onMenuItemClick(MenuItem item) {
				// TODO Auto-generated method stub
					
				ft = fragmentManager.beginTransaction().replace(R.id.frameLayoutFragment, cultureF);
				ft.addToBackStack(null);
				ft.commit();
				return false;
			}
		});
        
        
        MenuItem favoriteItem = submenu.getItem(2);
        favoriteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        favoriteItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			
			@Override
			public boolean onMenuItemClick(MenuItem item) {
				// TODO Auto-generated method stub
		//		ft = fragmentManager.beginTransaction().replace(R.id.frameLayoutFragment, favorite);
		//		ft.addToBackStack(null);
		//		ft.commit();
				return false;
			}
		});
        
        MenuItem settingItem = submenu.getItem(3);
        settingItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        settingItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			
			@Override
			public boolean onMenuItemClick(MenuItem item) {
				// TODO Auto-generated method stub
				//ft = fragmentManager.beginTransaction().replace(R.id.frameLayoutFragment, settings);
				//ft.addToBackStack(null);
				//ft.commit();		
				return false;
			}
		});
        
		
		com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
	      inflater.inflate(R.menu.activity_main, menu);
		return true;
		
	}
	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

        case android.R.id.home:
             finish();
             break;

        default:
            return super.onOptionsItemSelected(item);
        }
        return false;
    }

}
